package com.demo.swagger.controller.modulea;

import com.demo.swagger.BaseController;
import com.demo.swagger.BaseRequestBean;
import com.demo.swagger.User;
import io.swagger.annotations.*;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * @author sxx
 * @brief Demo controller
 * @details
 * @date 2017-08-12 15:10
 */
@Controller
@RequestMapping("/swaggerdemoa")
@Api(value = "/user", description = "Operations about user")
public class SwaggerControllerA extends BaseController{

//    @ResponseBody
    @RequestMapping(value = "/helloworld", method = RequestMethod.GET)
    @ApiOperation(nickname = "swagger-helloworld", value = "Swagger的世界", notes = "测试HelloWorld")
    public String helloWorld(@ApiParam(value = "昵称") @RequestParam String nickname) {
        return "Hello world, " + nickname;
    }

//    @ResponseBody
    @RequestMapping(value = "setCarouselRule.api",method = RequestMethod.POST)
    @ApiOperation(value = "test1",  notes = "notes1")
    public void setCarouselRule(HttpServletRequest request,
                                HttpServletResponse response,
                                BaseRequestBean<User> baseRequestBean) {
        HandleRequest(request,response);//处理基础对象
        baseRequestBean.resetResultObject(User.class);
        User bean = baseRequestBean.getResultObject(User.class);
        try {
            SetResponseFromCame(response, bean);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
//    @ResponseBody
    @RequestMapping(value = "setCarouselRule2.api")
    @ApiOperation(value = "test2", httpMethod = "POST GET",  notes = "notes2")
    public void setCarouselRule2(HttpServletRequest request,
                                HttpServletResponse response,
                                BaseRequestBean<List<User>> baseRequestBean) {
        HandleRequest(request,response);//处理基础对象
        baseRequestBean.resetArrayToResultObject(User.class);
        List<User> aaa = baseRequestBean.getResultObject(ArrayList.class);
        try {
            SetResponseFromCame(response, baseRequestBean);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
